﻿using CommunityToolkit.Mvvm.Input;
using SudukuSolver_Mvvm.ViewModels;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace SudukuSolver_Mvvm.Views;

/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.DataContext = new MainWindowViewModel();
        InitializeComponent();
    }

    private void LimitNumber_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        var isNum = new Regex("[^0-9]").IsMatch(e.Text); // 判断是否不是数字
        if (isNum)
        {
            e.Handled = true; // 如果不是数字，就将这个事件设置为已经处理了
        }
        else
        {
            e.Handled = false;
            ((TextBox)sender).Text = ""; // 如果是数字，就说明想输入一个新的数字，那就清空之前的数字
        }
    }

    private void TextBlock_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        TextBlock t = (TextBlock)sender;
        t.Text = e.Key.ToString();
    }

    private void TestButton_Click(object sender, RoutedEventArgs e)
    {
        MainWindowViewModel main = MainWindowViewModel.Instance;
        main.SudukuViewModel.Suduku[0][0].Cases = new List<int>();
    }
}
